import { applyDecorators, Type } from '@nestjs/common'
import { ApiExtraModels, ApiOkResponse, getSchemaPath } from '@nestjs/swagger'

export const ApiPaginatedOkResponse = <Model extends Type<any>>(
  model: Model,
) => {
  return applyDecorators(
    ApiExtraModels(model),
    ApiOkResponse({
      schema: {
        properties: {
          total: { type: 'number' },
          list: {
            type: 'array',
            items: { $ref: getSchemaPath(model) },
          },
        },
        required: ['total', 'list'],
      },
    }),
  )
}
